import { MenuService } from './menu.service'
import { Body, Controller, Delete, Get, Post, Query } from '@nestjs/common'
import { CreateMenuDTO, MenuEntity, UpdateMenuDTO, RequirePermission } from '@/common'

@Controller('system/menu')
export class MenuController {
  constructor(private readonly menuService: MenuService) {}

  /** 新增菜单 */
  @RequirePermission(['system:menu:create'])
  @Post('create')
  create(@Body() createDto: CreateMenuDTO) {
    return this.menuService.create(createDto)
  }

  /** 根据菜单 ID 删除单条数据 */
  @RequirePermission(['system:menu:delete'])
  @Delete('delete')
  deleteOneById(@Query('menuId') menuId: string) {
    return this.menuService.deleteOneById(menuId)
  }

  /** 更新菜单 */
  @RequirePermission(['system:menu:update'])
  @Post('update')
  update(@Body() updateDto: UpdateMenuDTO) {
    return this.menuService.update(updateDto)
  }

  /** 查询菜单列表 */
  @RequirePermission(['system:menu:query'])
  @Get('list')
  findList(@Query() queryParams: Partial<MenuEntity>) {
    return this.menuService.findList(queryParams)
  }

  /** 根据 id 查询单条菜单数据 */
  @RequirePermission(['system:menu:query'])
  @Get('detail')
  findOneById(@Query('menuId') menuId: string) {
    return this.menuService.findOneById(menuId)
  }

  /** 查询父级菜单下拉列表 */
  @Get('findParentList')
  @RequirePermission(['system:menu:query'])
  findParentList() {
    return this.menuService.findParentList()
  }
}
